var utils = require("../../utils/utils");
var ocrGml = require("../../utils/ocrGml");
var common = require("./common");
var ACTION = require("../../base/action");
var actionTreasure = new ACTION("开宝箱", {
  interval: null, //每个多少秒执行一次
  canStartHour: null, //最早可以开始的时间
  canStartHourEnd: null, //最晚可以开始的时间
  lastStartTime: null, //上一次的开始时间
  lastEndTime: null, //上一次的结束时间
  execSCount: 0, //执行成功次数
  execFCount: 0, //执行失败次数
  maxExecSCount: null, //最大成功执行次数
  maxExecFCount: null, //最大失败执行次数
  maxTotalExecCount: null, //最大总执行次数
  storage: common.storage,
});
actionTreasure.goStart = function () {
  if (common.inHome()) {
    sleep(utils.getRandom(1.5, 2, 1000));
    common.toTask();
    sleep(utils.getRandom(10, 12, 1000));
    return true;
  }
};
actionTreasure.exec = function () {
  var contents = ["点就领", "立即领取"];
  var ocrItem = ocrGml.captureExistOne(contents, true);
  if (ocrItem) {
    utils.clickOcrItem(ocrItem);
    sleep(utils.getRandom(2.5, 3, 1000));
    return;
  }
  var contents = ["明天领金币", "明天再来", "明日再来"];
  var ocrItem = ocrGml.captureExistOne(contents, true);
  if (ocrItem) {
    this.isOver = true;
    return;
  }
};
actionTreasure.afterExec = function () {
  var contents = ["先去看精彩视频"];
  for (var index = 0; index < contents.length; index++) {
    var content = contents[index];
    if (utils.clickTextStartsWith(content)) {
      console.log(this.name, "afterExec", "找到-" + content + "-");
      sleep(utils.getRandom(1.5, 2, 1000));
      return;
    }
  }
};

module.exports = actionTreasure;
